﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace Milan.Net
{
	/// <summary>
	/// Practical download strings
	/// </summary>
	public static class Download
	{
		public static List<string> Urls;
		/// <summary>
		/// Grabs a text file from the given URL.  If URL is null, then we iterate our URLs.
		/// </summary>
		/// <param name="url"></param>
		/// <returns>The text file or null on communication error.</returns>
		public static string GetTextFile(Uri url)
		{
			WebClient client = new WebClient();
			return client.DownloadString(url);
		}
		/// <summary>
		/// Copies a Web file via HTTP to a local file.
		/// </summary>
		/// <param name="url"></param>
		/// <param name="localFile"></param>
		public static void Copy(Uri url, string localFile)
		{
			string directory = Path.GetDirectoryName(localFile);
			if (!Directory.Exists(directory))
				Directory.CreateDirectory(directory);
			WebClient client = new WebClient();
			client.DownloadFile(url, localFile);
		}
	}
}
